home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Networking / Talking Heads / Sources / ez_adsp ƒ / Talking Head.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-13  |  24.5 KB  |  1,327 lines  |  [TEXT/KAHL]

  1.  
  2.  
  3. /* © 1989 Apple Computer, by Ricardo Batista */
  4.  
  5.  
  6. #include "ez_ADSP.h"
  7.  
  8. #define        open                0
  9. #define        prime                1
  10. #define        control                2
  11. #define        status                3
  12. #define        close                4
  13.  
  14.  
  15.  
  16. #define        GetZoneList        0x8000000
  17. #define        GetMyZone        0x7000000
  18.  
  19.  
  20. #define        okItem                1
  21. #define        cancelItem            2
  22.  
  23.  
  24. #define        _dName                "\p.ez_adsp"
  25.  
  26. #define        busyDlg                0
  27. #define        notfoundDlg            1
  28. #define        optionsDlg            2
  29. #define        listDlg                3
  30. #define        notLoadedDlg        4
  31. #define        usersDlg            5
  32.  
  33.  
  34. #define        boldBegin            3
  35. #define        boldEnd                4
  36. #define        bell                5
  37.  
  38.  
  39. #define        MaxDataSize            700
  40. #define        charW                7
  41. #define        charH                10
  42.  
  43. #define     modal_bit            (1<<7)
  44.  
  45. long signature;
  46. int ez;
  47. char buffer[600];
  48. WindowPtr myWindow;
  49. WindowRecord w;
  50. Rect bounds;
  51. int conectionFlag, oldFlag;
  52. DCtlPtr dce;
  53. cntrlParam ez_control;
  54. ioParam    io;
  55. ControlHandle sendB, optionsB, connectB, disconnectB;
  56. Rect InBox, OutBox;
  57. char InData[MaxDataSize], OutData[MaxDataSize];
  58. int InIndex[30], OutIndex[30];
  59. int InLines, OutLines;
  60. Point whereIn, whereOut;
  61. int LineIn, LineOut;
  62. int endCharIn, endCharOut;
  63. RgnHandle dummyRgn;
  64. Boolean boldIn, boldOut;
  65. long ticks;
  66. Boolean visible;
  67. Boolean reentrance;
  68.  
  69.  
  70. int main(ioParam* param, DCtlPtr d, int call);
  71. void MakeWindow(void);
  72. int MyRsrcID (int rsrcID);
  73. void myClose(void);
  74. int DoCommand(int menuItem);
  75. void DoEvent(cntrlParam* p);
  76. void SendFile(void);
  77. void Options(void);
  78. void Connect(Boolean skipZone);
  79. void Disconnect(void);
  80. void DoUpdate(void);
  81. void AdjustControls(void);
  82. void ChackStatus(void);
  83. Boolean GetAZone(EntityName *name);
  84. Boolean GetAddress(EntityName *name,AddrBlock *address);
  85. void CheckStatus(void);
  86. void SendName(void);
  87. void ShowErr(int dialog);
  88. void DoCursor(Boolean clear);
  89.  
  90. int main(param, d, call)
  91. ioParam *param;
  92. DCtlPtr d;
  93. int call;
  94. {
  95.     int err = 0;
  96.     cntrlParam *p;
  97.     
  98.     if (d->dCtlStorage == 0L) {
  99.         if (call == open) {
  100.             SysBeep(1);
  101.             return(openErr);
  102.         }
  103.         return(openErr);
  104.     }
  105.     if ((call != open) && (signature != 'RICK')) {
  106.         return(notOpenErr);
  107.     }
  108.     if (reentrance)
  109.         return(noErr);
  110.     reentrance = TRUE;
  111.     dce = d;
  112.     switch (call) {
  113.         case open:
  114.             d->dCtlFlags |= dNeedLock | dNeedTime | dNeedGoodBye | dCtlEnable;
  115.             d->dCtlDelay = 15;
  116.             InitCursor();
  117.             if (signature != 'RICK') {
  118.                 signature = 'RICK';
  119.                 err = OpenDriver("\p.MPP",&ez);
  120.                 if (!err)
  121.                     err = OpenDriver(_dName,&ez);
  122.                 if (err) {
  123.                     ShowErr(notLoadedDlg);
  124.                     return(err);
  125.                 }
  126.                 boldIn = boldOut = FALSE;
  127.                 conectionFlag = 0;
  128.                 oldFlag = -1;
  129.                 visible = FALSE;
  130.                 ticks = TickCount() + 30L;
  131.                 ez_control.ioRefNum = ez;
  132.                 ez_control.ioCompletion = 0L;
  133.                 ez_control.ioNamePtr = 0L;
  134.                 ez_control.ioVRefNum = 0;
  135.                 io.ioRefNum = ez;
  136.                 io.ioCompletion = 0L;
  137.                 io.ioNamePtr = 0L;
  138.                 io.ioVRefNum = 0;
  139.                 ez_control.csCode = autoFile;
  140.                 ez_control.csParam[0] = TRUE;
  141.                 err = PBControl(&ez_control,FALSE);
  142.                 ez_control.csCode = deskFlag;
  143.                 ez_control.csParam[0] = FALSE;
  144.                 err = PBControl(&ez_control,FALSE);
  145.                 ez_control.csCode = getBuf;
  146.                 err = PBStatus(&ez_control,FALSE);
  147.                 conectionFlag = ez_control.csParam[2];
  148.                 if (conectionFlag == 4)
  149.                     SysBeep(1);
  150.                 MakeWindow();
  151.             }
  152.             else
  153.                 SelectWindow(myWindow);
  154.             break;
  155.         case prime:
  156.             break;
  157.         case control:
  158.             p = (cntrlParam*) param;
  159.             switch (p->csCode) {
  160.                 case accRun:
  161.                     CheckStatus();
  162.                     DoCursor(FALSE);
  163.                     break;
  164.                 case accEvent:
  165.                     CheckStatus();
  166.                     DoEvent(p);
  167.                     break;
  168.                 case accMenu:
  169.                     DoCommand(p->csParam[1]);
  170.                     break;
  171.                 case goodBye:
  172.                     myClose();
  173.                     break;
  174.                 default:
  175.                     break;
  176.             }
  177.             break;
  178.         case close:
  179.             myClose();
  180.             break;
  181.         default:
  182.             break;
  183.     }
  184.     reentrance = FALSE;
  185.     return(err);
  186.     asm {
  187.         dc.l '© 19'
  188.         dc.l '89 A'
  189.         dc.l 'pple'
  190.         dc.l ' Com'
  191.         dc.l 'pute'
  192.         dc.l 'r, I'
  193.         dc.l 'nc. '
  194.         dc.l 'Rica'
  195.         dc.l 'rdo '
  196.         dc.l 'Bati'
  197.         dc.l 'sta.'
  198.     }
  199. }
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206. int DoCommand (menuItem)
  207. int menuItem;
  208. {
  209.     switch (menuItem)
  210.     {
  211.         case 1:
  212.             break;
  213.         default:
  214.             break;
  215.     }
  216. }
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226. void MakeWindow()
  227. {
  228.     Rect box;
  229.     register int c, middle;
  230.     GrafPtr savePort;
  231.     WindowPeek fw;
  232.     
  233.     InitCursor();
  234.     bounds.top = 40;
  235.     bounds.left = 20;
  236.     bounds.right = 350;
  237.     bounds.bottom = 310;
  238.     GetPort(&savePort);
  239.     fw = (WindowPeek) FrontWindow();
  240.     if (fw) {
  241.         if ((fw->windowKind == dialogKind) && (fw->spareFlag & modal_bit))
  242.             fw = 0L;
  243.         else
  244.             fw = (WindowPeek) -1L;
  245.     }
  246.     else
  247.         fw = (WindowPeek) -1L;
  248.     myWindow = NewWindow(&w,&bounds,"\pTalking Head...",1,noGrowDocProc,fw,1,0L);
  249.     SetPort(myWindow);
  250.     bounds.bottom -= bounds.top;
  251.     bounds.right -= bounds.left;
  252.     box = bounds;
  253.     box.bottom -= 6;
  254.     box.top = box.bottom - 20;
  255.     box.left = 6;
  256.     c = bounds.right / 4;
  257.     box.right = c;
  258.     sendB = NewControl(myWindow,&box,"\pSend File",1,0,0,1,0,0L);
  259.     box.left = box.right + 10;
  260.     box.right = c * 2;
  261.     optionsB = NewControl(myWindow,&box,"\pOptions",1,0,0,1,0,0L);
  262.     box.left = box.right + 10;
  263.     box.right = c * 3;
  264.     connectB = NewControl(myWindow,&box,"\pConnect",1,0,0,1,0,0L);
  265.     box.left = box.right + 11;
  266.     box.right = c * 4 - 1;
  267.     disconnectB = NewControl(myWindow,&box,"\pDisconnect",1,0,0,1,0,0L);
  268.     DrawControls(myWindow);
  269.     PenSize(1,1);
  270.     TextSize(9);
  271.     TextFont(1);
  272.     middle = bounds.bottom - 40;
  273.     MoveTo(0,middle + 6);
  274.     LineTo(bounds.right,middle + 6);
  275.     middle /= 2;
  276.     InBox.top = 10;
  277.     InBox.left = OutBox.left = 3;
  278.     InBox.right = OutBox.right = bounds.right - 3;
  279.     InBox.bottom = middle - 10;
  280.     MoveTo(0,middle);
  281.     LineTo(bounds.right,middle);
  282.     middle += 2;
  283.     OutBox.top = middle + 10;
  284.     OutBox.bottom = bounds.bottom - 30;
  285.     MoveTo(0,middle);
  286.     LineTo(bounds.right,middle);
  287.     dce->dCtlWindow = myWindow;
  288.     w.windowKind = dce->dCtlRefNum;
  289.     InIndex[0] = OutIndex[0] = 0;
  290.     InIndex[1] = OutIndex[1] = -1;
  291.     InData[0] = OutData[0] = 0;
  292.     OutLines = OutBox.bottom - OutBox.top;
  293.     OutLines /= charH;
  294.     InLines = InBox.bottom - InBox.top;
  295.     InLines /= charH;
  296.     OutLines--;
  297.     whereIn.h = whereOut.h = 3;
  298.     whereIn.v = InBox.top;
  299.     whereOut.v = OutBox.top;
  300.     LineIn = LineOut = 0;
  301.     endCharIn = endCharOut = 0;
  302.     dummyRgn = NewRgn();
  303.     SetPort(savePort);
  304. }
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314. void DoEvent (p)
  315. cntrlParam *p;
  316. {
  317.     char theChar;
  318.     long len;
  319.     ControlHandle theControl;
  320.     int part;
  321.     WindowPtr window;
  322.     Rect box;
  323.     EventRecord *myEvent, evt;
  324.     register int c;
  325.     int err;
  326.     Rect square;
  327.     Boolean commandKey;
  328.     GrafPtr savePort;
  329.     
  330.     BlockMove(&(p->csParam[0]),&myEvent,4L);
  331.     BlockMove(myEvent,&evt,(long) sizeof(EventRecord));
  332.     switch (evt.what)
  333.     {
  334.         case mouseDown:
  335.             GetPort(&savePort);
  336.             SetPort(myWindow);
  337.             GlobalToLocal(&evt.where);
  338.             if (FindControl(evt.where,myWindow,&theControl)) {
  339.                 if (TrackControl(theControl,evt.where,0L)) {
  340.                     if (theControl == sendB)
  341.                         SendFile();
  342.                     if (theControl == optionsB)
  343.                         Options();
  344.                     if (theControl == connectB) {
  345.                         if (evt.modifiers & cmdKey)
  346.                             Connect(TRUE);
  347.                         else
  348.                             Connect(FALSE);
  349.                     }
  350.                     if (theControl == disconnectB)
  351.                         Disconnect();
  352.                 }
  353.             }
  354.             SetPort(savePort);
  355.             break;
  356.         case keyDown: 
  357.         case autoKey:
  358.             GetPort(&savePort);
  359.             SetPort(myWindow);
  360.             theChar = evt.message & charCodeMask;
  361.             if (evt.modifiers & cmdKey)
  362.                 commandKey = TRUE;
  363.             else
  364.                 commandKey = FALSE;
  365.             io.ioReqCount = 1L;
  366.             io.ioBuffer = &theChar;
  367.             io.ioPosMode = 0;
  368.             io.ioPosOffset = 0;
  369.             if ((theChar > 14) && !commandKey) {
  370.                 if (visible)
  371.                     DoCursor(TRUE);
  372.                 if (boldOut)
  373.                     TextFace(bold);
  374.                 else
  375.                     TextFace(0);
  376.                 MoveTo(whereOut.h,whereOut.v);
  377.                 DrawChar(theChar);
  378.                 whereOut.h += charW;
  379.             }
  380.             if (theChar == '\b') {
  381.                 if (whereOut.h > 3) {
  382.                     if (visible)
  383.                         DoCursor(TRUE);
  384.                     whereOut.h -= charW;
  385.                     square.top = whereOut.v - charH + 1;
  386.                     square.bottom = whereOut.v + 3;
  387.                     square.left = whereOut.h;
  388.                     square.right = whereOut.h + charW;
  389.                     EraseRect(&square);
  390.                 }
  391.             }
  392.             if (theChar == '\r') {
  393.                 if (visible)
  394.                     DoCursor(TRUE);
  395.                 whereOut.h += charW;
  396.             }
  397.             if (commandKey) {
  398.                 if ((theChar == 'B') || (theChar == 'b')) {
  399.                     if (boldOut) {
  400.                         boldOut = FALSE;
  401.                         theChar = boldEnd;
  402.                     }
  403.                     else {
  404.                         boldOut = TRUE;
  405.                         theChar = boldBegin;
  406.                     }
  407.                 }
  408.                 if ((theChar == 'G') || (theChar == 'g'))
  409.                     theChar = bell;
  410.             }
  411.             err = PBWrite(&io,FALSE);
  412.             OutData[endCharOut] = theChar;
  413.             endCharOut++;
  414.             if (endCharOut == MaxDataSize)
  415.                 endCharOut = 0;
  416.             if (((whereOut.h + charW) > OutBox.right) || (theChar == 13)) {
  417.                 whereOut.v += charH;
  418.                 whereOut.h = 3;
  419.                 LineOut++;
  420.                 if (LineOut > OutLines) {
  421.                     LineOut = OutLines;
  422.                     OutBox.top -= charH - 2;
  423.                     OutBox.bottom -= 4;
  424.                     ScrollRect(&OutBox,0,-charH,dummyRgn);
  425.                     OutBox.top += charH - 2;
  426.                     whereOut.v -= charH;
  427.                     OutBox.bottom += 4;
  428.                     for (c = 0; c < OutLines; c++)
  429.                         OutIndex[c] = OutIndex[c + 1];
  430.                 }
  431.                 OutIndex[LineOut + 1] = -1;
  432.                 OutIndex[LineOut] = endCharOut;
  433.             }
  434.             SetPort(savePort);
  435.             break;
  436.         case updateEvt:
  437.             DoUpdate();
  438.             break;
  439.         case activateEvt:
  440.             ez_control.csCode = deskFlag;
  441.             ez_control.csParam[0] = FALSE;
  442.             err = PBControl(&ez_control,FALSE);
  443.             break;
  444.         default:
  445.             break;
  446.     }
  447. }
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456. void myClose()
  457. {
  458.     int err;
  459.     
  460.     CloseWindow(myWindow);
  461.     ez_control.csCode = deskFlag;
  462.     ez_control.csParam[0] = FALSE;
  463.     err = PBControl(&ez_control,FALSE);
  464.     ez_control.csCode = autoFile;
  465.     err = PBControl(&ez_control,FALSE);
  466.     if (conectionFlag == 4) {
  467.         ez_control.csCode = closeConn;
  468.         err = PBControl(&ez_control,FALSE);
  469.     }
  470.     dce->dCtlWindow = 0L;
  471.     dce->dCtlMenu = 0L;
  472. }
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483. void DoUpdate()
  484. {
  485.     register int middle, counter, index;
  486.     Point oldOut, oldIn;
  487.     Rect square;
  488.     GrafPtr savePort;
  489.     Rect cRect;
  490.     
  491.     oldIn = whereIn;
  492.     oldOut = whereOut;
  493.     GetPort(&savePort);
  494.     SetPort(myWindow);
  495.     if (visible) {
  496.         cRect.bottom = whereOut.v + 1;
  497.         cRect.left = whereOut.h;
  498.         cRect.top = cRect.bottom - 8;
  499.         cRect.right = cRect.left + 2;
  500.         InvalRect(&cRect);
  501.         visible = FALSE;
  502.     }
  503.     BeginUpdate(myWindow);
  504.     EraseRect(&(w.port.portRect));
  505.     DrawControls(myWindow);
  506.     PenSize(1,1);
  507.     TextSize(9);
  508.     TextFont(4);
  509.     middle = bounds.bottom - 40;
  510.     MoveTo(0,middle + 6);
  511.     LineTo(bounds.right,middle + 6);
  512.     middle /= 2;
  513.     MoveTo(0,middle);
  514.     LineTo(bounds.right,middle);
  515.     middle += 2;
  516.     MoveTo(0,middle);
  517.     LineTo(bounds.right,middle);
  518.     whereIn.h = whereOut.h = 3;
  519.     whereIn.v = InBox.top;
  520.     whereOut.v = OutBox.top;
  521.     counter = 0;
  522.     while (InIndex[counter] != -1) {
  523.         whereIn.h = 3;
  524.         index = InIndex[counter];
  525.         while ((index != endCharIn) && (index != InIndex[counter + 1])) {
  526.             if (InData[index] > 14) {
  527.                 MoveTo(whereIn.h,whereIn.v);
  528.                 DrawChar(InData[index]);
  529.                 whereIn.h += charW;
  530.             }
  531.             if (InData[index] == '\b') {
  532.                 if (whereIn.h > 3) {
  533.                     whereIn.h -= charW;
  534.                     square.top = whereIn.v - charH + 1;
  535.                     square.bottom = whereIn.v + 3;
  536.                     square.left = whereIn.h;
  537.                     square.right = whereIn.h + charW;
  538.                     EraseRect(&square);
  539.                 }
  540.             }
  541.             if (InData[index] == boldBegin)
  542.                 TextFace(bold);
  543.             if (InData[index] == boldEnd);
  544.                 TextFace(0);
  545.             if (InData[index] == '\r')
  546.                 whereIn.h += charW;    
  547.             index++;
  548.             if (index == MaxDataSize)
  549.                 index = 0;
  550.         }
  551.         whereIn.v += charH;
  552.         counter++;
  553.     }
  554.     counter = 0;
  555.     while (OutIndex[counter] != -1) {
  556.         whereOut.h = 3;
  557.         index = OutIndex[counter];
  558.         while ((index != endCharOut) && (index != OutIndex[counter + 1])) {
  559.             if (OutData[index] > 14) {
  560.                 MoveTo(whereOut.h,whereOut.v);
  561.                 DrawChar(OutData[index]);
  562.                 whereOut.h += charW;
  563.             }
  564.             if (OutData[index] == '\b') {
  565.                 if (whereOut.h > 3) {
  566.                     whereOut.h -= charW;
  567.                     square.top = whereOut.v - charH + 1;
  568.                     square.bottom = whereOut.v + 3;
  569.                     square.left = whereOut.h;
  570.                     square.right = whereOut.h + charW;
  571.                     EraseRect(&square);
  572.                 }
  573.             }
  574.             if (OutData[index] == '\r')
  575.                 whereOut.h += charW;    
  576.             if (OutData[index] == boldBegin)
  577.                 TextFace(bold);
  578.             if (OutData[index] == boldEnd)
  579.                 TextFace(0);
  580.             index++;
  581.             if (index == MaxDataSize)
  582.                 index = 0;
  583.         }
  584.         whereOut.v += charH;
  585.         counter++;
  586.     }
  587.     EndUpdate(myWindow);
  588.     SetPort(savePort);
  589.     whereOut = oldOut;
  590.     whereIn = oldIn;
  591. }
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. int MyRsrcID (rsrcID)
  599. int     rsrcID;
  600. {
  601.     return (0xC000 | ~(dce->dCtlRefNum) << 5 | rsrcID);
  602. }
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612. void SendFile()
  613. {
  614.     SFReply reply;
  615.     Point where;
  616.     Ptr p;
  617.     int err;
  618.     
  619.     where.h = where.v = 100;
  620.     SFGetFile(where,"\pSelect a file:",0L,-1,0L,0L,&reply);
  621.     if (reply.good) {
  622.         dce->dCtlFlags -= dNeedTime;
  623.         SetCursor(*GetCursor(watchCursor));
  624.         DoUpdate();
  625.         ez_control.csCode = sendFile;
  626.         p = (Ptr) &reply.fName[0];
  627.         BlockMove(&p,&(ez_control.csParam[0]),4L);
  628.         ez_control.csParam[2] = reply.vRefNum;
  629.         err = PBControl(&ez_control,FALSE);
  630.         InitCursor();
  631.         dce->dCtlFlags |= dNeedLock | dNeedTime | dNeedGoodBye | dCtlEnable;
  632.     }
  633. }
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644. void Options()
  645. {
  646.     GrafPtr savePort;
  647.     int id, item;
  648.     DialogPtr aDialog;
  649.     DialogRecord d;
  650.     ControlHandle H, answerControl;
  651.     Rect box;
  652.     int err;
  653.     
  654.     GetPort(&savePort);
  655.     id = MyRsrcID(optionsDlg);
  656.     aDialog = GetNewDialog(id,&d,-1L);
  657.     SetPort(aDialog);
  658.     GetDItem(aDialog,1,&item,&H,&box);
  659.     DrawDialog(aDialog);
  660.     PenSize(3,3);
  661.     InsetRect(&box,-4,-4);
  662.     FrameRoundRect(&box,16,16);
  663.     PenNormal();
  664.     GetDItem(aDialog,2,&item,&answerControl,&box);
  665.     item = 0;
  666.     while (item != 1) {
  667.         ModalDialog(0L,&item);
  668.         if (item == 2) {
  669.             if (GetCtlValue(answerControl))
  670.                 SetCtlValue(answerControl,0);
  671.             else
  672.                 SetCtlValue(answerControl,1);
  673.         }
  674.     }
  675.     if (GetCtlValue(answerControl))
  676.         ez_control.csCode = disable;
  677.     else
  678.         ez_control.csCode = enable;
  679.     err = PBControl(&ez_control,FALSE);
  680.     CloseDialog(aDialog);
  681.     SetPort(savePort);
  682. }
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693. void Connect(skipZone)
  694. Boolean skipZone;
  695. {
  696.     AddrBlock address;
  697.     EntityName name;
  698.     int err;
  699.     
  700.     name.objStr[0] = 1;
  701.     name.objStr[1] = '=';
  702.     name.zoneStr[0] = 1;
  703.     name.zoneStr[1] = '*';
  704.     BlockMove("\pTalking Head",&(name.typeStr[0]),14L);
  705.     if (skipZone || GetAZone(&name)) {
  706.         if (GetAddress(&name,&address)) {
  707.             ez_control.csCode = openConn;
  708.             BlockMove(&address,&(ez_control.csParam[0]),(long) sizeof(AddrBlock));
  709.             err = PBControl(&ez_control,FALSE);
  710.             if (err)
  711.                 ShowErr(busyDlg);
  712.             else {
  713.                 SendName();
  714.                 SetWTitle(myWindow,name.objStr);
  715.             }
  716.         }
  717.     }
  718. }
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729. void SendName()
  730. {
  731.     StringHandle str;
  732.     int temp;
  733.     int err;
  734.     
  735.     str = (StringHandle) GetString(-16096);
  736.     if (str) {
  737.         HLock(str);
  738.         BlockMove(*str,&buffer[0],34L);
  739.         HUnlock(str);
  740.         ReleaseResource(str);
  741.     }
  742.     else
  743.         BlockMove("\pUnidentified",&buffer[0],20L);
  744.     io.ioReqCount = 1L;
  745.     io.ioBuffer = (Ptr) &"\001      ";
  746.     io.ioPosMode = 0;
  747.     io.ioPosOffset = 0;
  748.     err = PBWrite(&io,FALSE);
  749.     temp = buffer[0];
  750.     io.ioReqCount = temp + 1;
  751.     io.ioBuffer = &buffer[0];
  752.     err = PBWrite(&io,FALSE);
  753. }
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763. void Disconnect()
  764. {
  765.     int err;
  766.     
  767.     ez_control.csCode = closeConn;
  768.     err = PBControl(&ez_control,FALSE);
  769. }
  770.  
  771.  
  772.  
  773.  
  774.  
  775. void AdjustControls()
  776. {
  777.     GrafPtr savePort;
  778.     
  779.     GetPort(&savePort);
  780.     SetPort(myWindow);
  781.     if ((conectionFlag == 2) || (conectionFlag == 6)) {
  782.         HiliteControl(connectB,0);
  783.         HiliteControl(disconnectB,255);
  784.         HiliteControl(optionsB,0);
  785.         HiliteControl(sendB,255);
  786.         SetWTitle(myWindow,"\pTalking Head...");
  787.     }
  788.     if (conectionFlag == 4) {
  789.         HiliteControl(connectB,255);
  790.         HiliteControl(disconnectB,0);
  791.         HiliteControl(optionsB,0);
  792.         HiliteControl(sendB,0);
  793.     }
  794.     SetPort(savePort);
  795.     oldFlag = conectionFlag;
  796. }
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805. void CheckStatus()
  806. {
  807.     long len = 0L;
  808.     register int c, c2;
  809.     char name[40];
  810.     int limit;
  811.     int err;
  812.     Rect square;
  813.     GrafPtr savePort;
  814.     
  815.     ez_control.csCode = getBuf;
  816.     err = PBStatus(&ez_control,FALSE);
  817.     BlockMove(&(ez_control.csParam[0]),&len,4L);
  818.     conectionFlag = ez_control.csParam[2];
  819.     GetPort(&savePort);
  820.     SetPort(myWindow);
  821.     if (conectionFlag != oldFlag)
  822.         AdjustControls();
  823.     if (len) {
  824.         if (len > 512)
  825.             len = 512;
  826.         io.ioActCount = 0L;
  827.         io.ioReqCount = len;
  828.         io.ioBuffer = &buffer[0];
  829.         io.ioPosMode = 0;
  830.         io.ioPosOffset = 0;
  831.         err = PBRead(&io,FALSE);
  832.         len = io.ioActCount;
  833.         for (c = 0; c < len; c++) {
  834.             if (buffer[c] == 1) {
  835.                 c++;
  836.                 limit = buffer[c] + 1;
  837.                 for (c2 = 0; c2 < limit; c2++, c++)
  838.                     name[c2] = buffer[c];
  839.                 SetWTitle(myWindow,name);
  840.                 if (c == len)
  841.                     return;
  842.             }
  843.             if ((buffer[c] != 13) && (buffer[c] != '\b')) {
  844.                 if (boldIn)
  845.                     TextFace(bold);
  846.                 else
  847.                     TextFace(0);
  848.                 MoveTo(whereIn.h,whereIn.v);
  849.                 DrawChar(buffer[c]);
  850.                 whereIn.h += charW;
  851.             }
  852.             if (buffer[c] == '\b') {
  853.                 if (whereIn.h > 3) {
  854.                     whereIn.h -= charW;
  855.                     square.top = whereIn.v - charH + 1;
  856.                     square.bottom = whereIn.v + 3;
  857.                     square.left = whereIn.h;
  858.                     square.right = whereIn.h + charW;
  859.                     EraseRect(&square);
  860.                 }
  861.             }
  862.             if (buffer[c] == boldBegin)
  863.                 boldIn = TRUE;
  864.             if (buffer[c] == boldEnd)
  865.                 boldIn = FALSE;
  866.             if (buffer[c] == bell)
  867.                 SysBeep(1);
  868.             if (buffer[c] == '\r')
  869.                 whereIn.h += charW;
  870.             InData[endCharIn] = buffer[c];
  871.             endCharIn++;
  872.             if (endCharIn == MaxDataSize)
  873.                 endCharIn = 0;
  874.             if (((whereIn.h + charW) > InBox.right) || (buffer[c] == 13)) {
  875.                 whereIn.v += charH;
  876.                 whereIn.h = 3;
  877.                 LineIn++;
  878.                 if (LineIn > InLines) {
  879.                     LineIn = InLines;
  880.                     whereIn.v -= charH;
  881.                     InBox.top -= charH - 2;
  882.                     ScrollRect(&InBox,0,-charH,dummyRgn);
  883.                     InBox.top += charH - 2;
  884.                     for (c2 = 0; c2 < InLines; c2++)
  885.                         InIndex[c2] = InIndex[c2 + 1];
  886.                 }
  887.                 InIndex[LineIn + 1] = -1;
  888.                 InIndex[LineIn] = endCharIn;
  889.             }
  890.         }
  891.     }
  892.     SetPort(savePort);
  893. }
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902. Boolean GetAZone(name)
  903. EntityName *name;
  904. {
  905.     int abridge;
  906.     DialogPtr aDialog;
  907.     Point where;
  908.     ListHandle z;
  909.     int item,node,net,howMany,zones,err;
  910.     Rect zBox,bounds;
  911.     long ourData;
  912.     Point cell;
  913.     Handle H;
  914.     Boolean done = FALSE;
  915.     unsigned char dummy[4];
  916.     register int counter,index;
  917.     char aBuf[600];
  918.     int id, datalen;
  919.     Boolean doubleClick;
  920.     DialogRecord d;
  921.     Rect box;
  922.     GrafPtr savePort;
  923.     ATPParamBlock a;
  924.     BDSElement bds;
  925.     
  926.     SetCursor(*GetCursor(watchCursor));
  927.     asm {
  928.         move.l 0x2D8,a0
  929.         clr.w abridge
  930.         move.b 0x19(a0),abridge+1
  931.         move.w 0x1A(a0),net
  932.         clr.w node
  933.         move.b (a0),node+1
  934.     }
  935.     if (abridge == 0)
  936.         return(TRUE);
  937.     GetPort(&savePort);
  938.     id = MyRsrcID(listDlg);
  939.     aDialog = GetNewDialog(id,&d,-1L);
  940.     SetPort(aDialog);
  941.     GetDItem(aDialog,4,&item,&H,&zBox);
  942.     DrawDialog(aDialog);
  943.     SetRect(&bounds,0,0,0,0);
  944.     zBox.right -= 15;
  945.     cell.h = cell.v = 0;
  946.     z = LNew(&zBox,&bounds,cell,0,aDialog,TRUE,FALSE,FALSE,TRUE);
  947.     (*z)->selFlags |= lNoNilHilite + lNoRect + lNoExtend + lNoDisjoint + lOnlyOne;
  948.     zBox.top--;
  949.     zBox.left--;
  950.     zBox.right++;
  951.     zBox.bottom++;
  952.     LActivate(TRUE,z);
  953.     LAutoScroll(z);
  954.     LAddColumn(1,0,z);
  955.     FrameRect(&zBox);
  956.     howMany = zones = 0;
  957.     cell.v = cell.h = 0;
  958.     ourData = 0;
  959.     a.userData = GetZoneList;
  960.     a.atpFlags = 0;
  961.     a.addrBlock.aNode = abridge;
  962.     a.addrBlock.aNet = net;
  963.     a.addrBlock.aSocket = 6;
  964.     a.reqLength = 0;
  965.     a.reqPointer = 0L;
  966.     a.ATPnumOfBuffs = 1;
  967.     a.ATPtimeOutVal = 4;
  968.     a.ATPretryCount = 3;
  969.     a.bdsPointer = (Ptr) &bds;
  970.     bds.buffSize = 600;
  971.     bds.dataSize = 0;
  972.     bds.userBytes = 0L;
  973.     bds.buffPtr = (Ptr) aBuf;
  974.     aBuf[0] = 0;
  975.     ourData = 1;
  976.     FrameRect(&zBox);
  977.     zones = 0;
  978.     while (!done) {
  979.         ourData |= GetZoneList;
  980.         a.userData = ourData;
  981.         err = PSendRequest(&a,FALSE);
  982.         if (err) {
  983.             done = TRUE;
  984.             zones = 0;
  985.         }
  986.         BlockMove(&bds.userBytes,&dummy[0],4L);
  987.         BlockMove(&dummy[2],&howMany,2L);
  988.         zones += howMany;
  989.         ourData = zones;
  990.         if (!done) {
  991.             if (howMany)
  992.                 LAddRow(howMany,zones,z);
  993.             for (counter = 0, index = 0; counter < howMany; counter++) {
  994.                 LSetCell(&aBuf[index + 1],(int) aBuf[index],cell,z);
  995.                 cell.v++;
  996.                 index += aBuf[index] + 1;
  997.             }
  998.             FrameRect(&zBox);
  999.         }
  1000.         if (!done)
  1001.             done = dummy[0];
  1002.     }
  1003.     if (zones) {
  1004.         a.userData = GetMyZone;
  1005.         err = PSendRequest(&a,FALSE);
  1006.         cell.v = cell.h = 0;
  1007.         datalen = aBuf[0];
  1008.         LSearch(&aBuf[1],datalen,0L,&cell,z);
  1009.         LSetSelect(TRUE,cell,z);
  1010.         LAutoScroll(z);
  1011.     }
  1012.     GetDItem(aDialog,1,&item,&H,&box);
  1013.     if (zones) {
  1014.         PenSize(3,3);
  1015.         InsetRect(&box,-4,-4);
  1016.         FrameRoundRect(&box,16,16);
  1017.         PenNormal();
  1018.     }
  1019.     else
  1020.         HiliteControl(H,255);
  1021.     InitCursor();
  1022.     item = cell.v = 0;
  1023.     while ((item != okItem) && (item != cancelItem)) {
  1024.         ModalDialog(0L,&item);
  1025.         if (item == 4) {
  1026.             cell.v = 0;
  1027.             GetMouse(&where);
  1028.             doubleClick = LClick(where,0,z);
  1029.             asm {
  1030.                 clr.l -(sp)                ; space for cell result
  1031.                 move.l z,-(sp)            ; push the list handle
  1032.                 move.w #64,-(sp)        ; push LLastClick selector
  1033.                 _Pack0                    ; do it
  1034.                 move.l (sp)+,cell        ; put in cell
  1035.             }
  1036.             if (doubleClick && (cell.v != -1))
  1037.                 item = 1;
  1038.         }
  1039.         if ((item == 1) && zones) {
  1040.             cell.v = cell.h = 0;
  1041.             if (!LGetSelect(TRUE,&cell,z)) {
  1042.                 name->zoneStr[0] = 1;
  1043.                 name->zoneStr[1] = '*';
  1044.             }
  1045.             else {
  1046.                 datalen = 33;
  1047.                 LGetCell(&(name->zoneStr[1]),&datalen,cell,z);
  1048.                 name->zoneStr[0] = datalen;
  1049.             }
  1050.         }
  1051.         else {
  1052.             if (item == 1)
  1053.                 item = 2;
  1054.         }
  1055.     }
  1056.     LDispose(z);
  1057.     CloseDialog(aDialog);
  1058.     SetPort(savePort);
  1059.     if (item == 2)
  1060.         return(FALSE);
  1061.     return(TRUE);
  1062. }
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076. Boolean GetAddress(name,address)
  1077. EntityName *name;
  1078. AddrBlock *address;
  1079. {
  1080.     MPPParamBlock p;
  1081.     int id, datalen;
  1082.     Rect box;
  1083.     char buffer[5000];
  1084.     EntityName newName;
  1085.     AddrBlock newAddress;
  1086.     DialogPtr aDialog;
  1087.     Point where;
  1088.     ListHandle z;
  1089.     int item,node,net,howMany,zones,err;
  1090.     Rect zBox,bounds;
  1091.     Point cell;
  1092.     Handle H;
  1093.     register int counter,index;
  1094.     Boolean doubleClick;
  1095.     DialogRecord d;
  1096.     GrafPtr savePort;
  1097.     
  1098.     SetCursor(*GetCursor(watchCursor));
  1099.     GetPort(&savePort);
  1100.     id = MyRsrcID(listDlg);
  1101.     aDialog = GetNewDialog(id,&d,-1L);
  1102.     SetPort(aDialog);
  1103.     GetDItem(aDialog,4,&item,&H,&zBox);
  1104.     GetDItem(aDialog,3,&item,&H,&box);
  1105.     SetIText(H,"\pPlease select a Talking Head :");
  1106.     DrawDialog(aDialog);
  1107.     SetRect(&bounds,0,0,0,0);
  1108.     zBox.right -= 15;
  1109.     cell.h = cell.v = 0;
  1110.     z = LNew(&zBox,&bounds,cell,0,aDialog,TRUE,FALSE,FALSE,TRUE);
  1111.     (*z)->selFlags = lNoNilHilite + lNoRect + lNoExtend + lNoDisjoint + lOnlyOne;
  1112.     zBox.top--;
  1113.     zBox.left--;
  1114.     zBox.right++;
  1115.     zBox.bottom++;
  1116.     LActivate(TRUE,z);
  1117.     LAutoScroll(z);
  1118.     LAddColumn(1,0,z);
  1119.     FrameRect(&zBox);
  1120.     index = name->objStr[0] + 1;
  1121.     BlockMove(&(name->typeStr[0]),&(name->objStr[index]),33L);
  1122.     index += name->objStr[index] + 1;
  1123.     BlockMove(&(name->zoneStr[0]),&(name->objStr[index]),33L);
  1124.     p.NBPinterval = 5;
  1125.     p.NBPcount = 5;
  1126.     p.NBPentityPtr = (Ptr) name;
  1127.     p.NBPretBuffPtr = buffer;
  1128.     p.NBPretBuffSize = 5000;
  1129.     p.NBPmaxToGet = 45;
  1130.     err = PLookupName(&p,FALSE);
  1131.     howMany = p.NBPnumGotten;
  1132.     cell.v = cell.h = 0;
  1133.     LAddRow(howMany,0,z);
  1134.     LAddColumn(1,0,z);
  1135.     for (counter = 0; counter < howMany; counter++) {
  1136.         myNBPExtract(&buffer[0],howMany,counter + 1,&newName,&newAddress);
  1137.         datalen = newName.objStr[0];
  1138.         cell.h = 0;
  1139.         LSetCell(&(newName.objStr[1]),datalen,cell,z);
  1140.         datalen = 4;
  1141.         cell.h = 1;
  1142.         LSetCell(&newAddress,datalen,cell,z);
  1143.         cell.v++;
  1144.     }
  1145.     FrameRect(&zBox);
  1146.     GetDItem(aDialog,1,&item,&H,&box);
  1147.     if (howMany) {
  1148.         cell.v = cell.h = 0;
  1149.         LSetSelect(TRUE,cell,z);
  1150.         PenSize(3,3);
  1151.         InsetRect(&box,-4,-4);
  1152.         FrameRoundRect(&box,16,16);
  1153.         PenNormal();
  1154.     }
  1155.     else {
  1156.         HiliteControl(H,255);
  1157.     }
  1158.     InitCursor();
  1159.     item = cell.v = cell.h = 0;
  1160.     while ((item != 1) && (item != 2)) {
  1161.         ModalDialog(0L,&item);
  1162.         if ((item == 4) && howMany) {
  1163.             cell.v = 0;
  1164.             GetMouse(&where);
  1165.             doubleClick = LClick(where,0,z);
  1166.             asm {
  1167.                 clr.l -(sp)                ; space for cell result
  1168.                 move.l z,-(sp)            ; push the list handle
  1169.                 move.w #64,-(sp)        ; push LLastClick selector
  1170.                 _Pack0                    ; do it
  1171.                 move.l (sp)+,cell        ; put in cell
  1172.             }
  1173.             if (cell.v < 0)
  1174.                 cell.v = cell.h = 0;
  1175.             LSetSelect(TRUE,cell,z);
  1176.             if (doubleClick)
  1177.                 item = 1;
  1178.         }
  1179.         if ((item == 1) && howMany) {
  1180.             cell.v = cell.h = 0;
  1181.             LGetSelect(TRUE,&cell,z);
  1182.             datalen = 33;
  1183.             cell.h = 1;
  1184.             LGetCell(address,&datalen,cell,z);
  1185.             datalen = 33;
  1186.             cell.h = 0;
  1187.             LGetCell(&(name->objStr[1]),&datalen,cell,z);
  1188.             name->objStr[0] = datalen;
  1189.         }
  1190.         else {
  1191.             if (item == 1)
  1192.                 item = 2;
  1193.         }
  1194.     }
  1195.     LDispose(z);
  1196.     CloseDialog(aDialog);
  1197.     SetPort(savePort);
  1198.     if (item == 2)
  1199.         return(FALSE);
  1200.     return(TRUE);
  1201. }
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212. void ShowErr(dialog)
  1213. int dialog;
  1214. {
  1215.     GrafPtr savePort;
  1216.     int id, item;
  1217.     DialogPtr aDialog;
  1218.     DialogRecord d;
  1219.     ControlHandle H;
  1220.     Rect box;
  1221.     
  1222.     GetPort(&savePort);
  1223.     if (dialog == notLoadedDlg)
  1224.         SysBeep(1);
  1225.     id = MyRsrcID(dialog);
  1226.     aDialog = GetNewDialog(id,&d,-1L);
  1227.     SetPort(aDialog);
  1228.     DrawDialog(aDialog);
  1229.     GetDItem(aDialog,1,&item,&H,&box);
  1230.     InsetRect(&box,-4,-4);
  1231.     PenSize(3,3);
  1232.     FrameRoundRect(&box,16,16);
  1233.     PenNormal();
  1234.     item = 0;
  1235.     while (item != 1)
  1236.         ModalDialog(0L,&item);
  1237.     CloseDialog(aDialog);
  1238.     SetPort(savePort);
  1239. }
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250. void DoCursor(clear)
  1251. Boolean clear;
  1252. {
  1253.     Rect cRect;
  1254.     GrafPtr savePort;
  1255.     Boolean erase = FALSE;
  1256.     
  1257.     if (clear || (ticks < TickCount()))
  1258.         ticks = TickCount() + 30L;
  1259.     else
  1260.         return;
  1261.     if (visible)
  1262.         visible = FALSE;
  1263.     else
  1264.         visible = TRUE;
  1265.     GetPort(&savePort);
  1266.     SetPort(myWindow);
  1267.     cRect.bottom = whereOut.v + 1;
  1268.     cRect.left = whereOut.h;
  1269.     cRect.top = cRect.bottom - 8;
  1270.     cRect.right = cRect.left + 2;
  1271.     InvertRect(&cRect);
  1272.     SetPort(savePort);
  1273. }
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285. /*
  1286.     This function extracts names and addresses out of a buffer filled by NBP
  1287. */
  1288.  
  1289.  
  1290. int myNBPExtract(buffer,howMany,which,Name,Addr)
  1291. char *buffer;
  1292. int howMany;
  1293. int which;
  1294. EntityName *Name;
  1295. AddrBlock *Addr;
  1296. {
  1297.     char *p;
  1298.     register int index = 1, nameCounter = 0;
  1299.     
  1300.     p = buffer;
  1301.     while ((index < which) && (index < howMany)) {
  1302.         p += 5;    /* skip addr and enumerator */
  1303.         p += (*p) + 1;    /* skip name */
  1304.         p += (*p) + 1;    /* skip type */
  1305.         p += (*p) + 1;    /* skip zone */
  1306.         index++;
  1307.     }
  1308.     BlockMove(p,Addr,4L);
  1309.     p += 5;
  1310.     BlockMove(p,Name->objStr,33L);
  1311.     p += (*p) + 1;
  1312.     BlockMove(p,Name->typeStr,33L);
  1313.     p += (*p) + 1;
  1314.     BlockMove(p,Name->zoneStr,33L);
  1315.     return(0);
  1316. }
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.